package com.usian.controller;


import com.usian.pojo.Bumen;
import com.usian.pojo.Function;
import com.usian.service.CompanyService;
import com.usian.service.FunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/function")
public class FunctionController {
    @Autowired
    private FunctionService functionService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Function> list = functionService.findAll();
        model.addAttribute("function",list);
        return "function";
    }
    @Autowired
    private CompanyService companyService;

    @RequestMapping("/toadd")
    public String toadd(Model model){
        List<Bumen> bumen = companyService.findBumen();
        model.addAttribute("bumen",bumen);
        return "addFunction";
    }

    @RequestMapping("/add")
    public String add(Function function){
        functionService.add(function);
        return "redirect:/function/findAll";
    }

    @RequestMapping("/toupdate")
    public String toupdate(Model model,Integer zid){
        Function function = functionService.findById(zid);
        model.addAttribute("function",function);
        List<Bumen> bumen = companyService.findBumen();
        model.addAttribute("bumen",bumen);
        return "updateFunction";
    }

    @RequestMapping("update")
    public String update(Function function,Model model){
        functionService.update(function);
        return "redirect:/function/findAll";
    }

    @RequestMapping("del")
    public String del(Integer zid) {
        boolean del = functionService.del(zid);
        return "redirect:/function/findAll";

    }


}
